﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Assets.Scripts
{
    public class BaseScripts : MonoBehaviour
    {
        static readonly Dictionary<string, GameObject> gameObjectCache = new Dictionary<string, GameObject>();

        public GameObject FindGameObject(string name)
        {

            if (!gameObjectCache.ContainsKey(name))
            {
                var games = Resources.FindObjectsOfTypeAll<GameObject>();
                for (int i = 0; i < games.Length; i++)
                {
                    if (games[i].name == name)
                    {
                        gameObjectCache[name] = games[i];
                        break;
                    }
                }
            }
            return gameObjectCache[name];
        }

    }
}
